package suanfa.datastructure.queue;

public class Queue<T> {

    public int front=-1;
    public int rear=-1;
    public T[] arr;
    int capacity=3;
    int size=0;


    public Queue(int capacity){
        arr=(T[])new Object[capacity];
        size=0;
    }

    public Queue(){
        arr=(T[])new Object[this.capacity];
        size=0;
    }

    public int getsize(){
        return this.size;
    }

    public boolean isEmpty(){
        return this.size==0;
    }

    public void enqueue(T data){
        if(isEmpty()){
            arr[front++]=data;
            rear++;
            size++;
        }
        else{
            if(rear==arr.length-1){
                System.out.println("已满");
                return;
            }
            arr[rear++]=data;
            size++;
        }
    }

    public T dequeue(){
        if(isEmpty()){
            System.out.println("已空");
            return null;
        }
            size--;

        return arr[front++];
    }

    public static void main(String[] args) {
        Queue q=new Queue<Integer>();
        q.enqueue(1);
        q.enqueue(2);
        q.enqueue(3);

    }
}
